package domain;

import enums.BaseResponseEnum;
import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResponse implements Serializable {

    private static final long serialVersionUID = 9527L;

    protected long errCode;
    protected String errMsg;

    protected Object result;

    public BaseResponse() {
        this.errCode = BaseResponseEnum.SUCCESS.getErrCode();
        this.errMsg = BaseResponseEnum.SUCCESS.getErrMsg();
    }

    public BaseResponse(BaseResponseEnum responseEnum) {
        this.errCode = responseEnum.getErrCode();
        this.errMsg = responseEnum.getErrMsg();
    }

    public BaseResponse(Object result) {
        this.errCode = BaseResponseEnum.SUCCESS.getErrCode();
        this.errMsg = BaseResponseEnum.SUCCESS.getErrMsg();
        this.result = result;
    }

    public static BaseResponse success() {
        BaseResponse success = new BaseResponse();
        return success;
    }

    public static BaseResponse error() {
        BaseResponse error = new BaseResponse();
        error.setErrCode(BaseResponseEnum.ERROR.getErrCode());
        error.setErrMsg(BaseResponseEnum.ERROR.getErrMsg());
        return error;
    }

    public static BaseResponse success(Object result) {
        BaseResponse success = success();
        success.setResult(result);
        return success;
    }

}